<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>基本演示</legend>
</fieldset>
<div class="layui-btn-container">
    <button type="button" class="layui-btn layui-btn-sm" lay-demo="getChecked">获取选中节点数据</button>
    <button type="button" class="layui-btn layui-btn-sm" lay-demo="setChecked">勾选指定节点</button>
    <button type="button" class="layui-btn layui-btn-sm" lay-demo="reload">重载实例</button>
</div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>相册管理</legend>
</fieldset>

<div id="test9" class="demo-tree demo-tree-box" style="overflow: scroll;"></div>
<script>
    layui.use(['tree', 'util', 'jquery'], function () {
        var tree = layui.tree
            , layer = layui.layer
            , util = layui.util
            , $ = layui.jquery;
        var data = [
            {
                title: '2019届',
                id: 1,
                children: [
                    {
                        title: '计算机与信息工程学院',
                        id: 1000,
                        children: [
                            {
                                title: '数据科学与大数据技术'
                                , id: 10001,
                                children: [
                                    {
                                        title: '19-3'
                                        , id: 10002
                                        , children: [
                                            {
                                                title: 'test',
                                                id: 100021
                                            }]
                                    }]
                            }]
                    },
                    {
                        title: '文学院'
                        , id: 1001
                    },
                    {
                        title: '数学院'
                        , id: 1002
                    }]
            },
            {
                title: '广西'
                , id: 2
                , children: [
                    {
                        title: '南宁'
                        , id: 2000
                    }, {
                        title: '桂林'
                        , id: 2001
                    }]
            },
            {
                title: '陕西'
                , id: 3
                , children: [
                    {
                        title: '西安'
                        , id: 3000
                    }, {
                        title: '延安'
                        , id: 3001
                    }]
            }];
        console.log(data)
        console.log(data.toString())

        //按钮事件
        util.event('lay-demo', {
            getChecked: function (othis) {
                var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据

                layer.alert(JSON.stringify(checkedData), {shade: 0});
                console.log(checkedData);
            }
            , setChecked: function () {
                tree.setChecked('demoId1', [12, 16]); //勾选指定节点
            }
            , reload: function () {
                //重载实例
                tree.reload('demoId1', {});

            }
        });
        //开启节点操作图标
        tree.render({
            elem: '#test9'
            , data: data
            , edit: ['add', 'update', 'del'] //操作节点的图标
            , click: function (obj) {
                layer.msg(JSON.stringify(obj.data));
            }
        });
    });
</script>